// Copyright (c) Lawrence Livermore National Security, LLC and other VisIt
// Project developers.  See the top-level LICENSE file for dates and other
// details.  No copyright assignment is required to contribute to VisIt.

#include <TessellateAttributes.h>
#include <DataNode.h>

// ****************************************************************************
// Method: TessellateAttributes::TessellateAttributes
//
// Purpose:
//   Init utility for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void TessellateAttributes::Init()
{
    chordError = 0.035;
    fieldCriterion = 0.035;
    mergePoints = true;

    TessellateAttributes::SelectAll();
}

// ****************************************************************************
// Method: TessellateAttributes::TessellateAttributes
//
// Purpose:
//   Copy utility for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void TessellateAttributes::Copy(const TessellateAttributes &obj)
{
    chordError = obj.chordError;
    fieldCriterion = obj.fieldCriterion;
    mergePoints = obj.mergePoints;

    TessellateAttributes::SelectAll();
}

// Type map format string
const char *TessellateAttributes::TypeMapFormatString = TESSELLATEATTRIBUTES_TMFS;
const AttributeGroup::private_tmfs_t TessellateAttributes::TmfsStruct = {TESSELLATEATTRIBUTES_TMFS};


// ****************************************************************************
// Method: TessellateAttributes::TessellateAttributes
//
// Purpose:
//   Default constructor for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

TessellateAttributes::TessellateAttributes() :
    AttributeSubject(TessellateAttributes::TypeMapFormatString)
{
    TessellateAttributes::Init();
}

// ****************************************************************************
// Method: TessellateAttributes::TessellateAttributes
//
// Purpose:
//   Constructor for the derived classes of TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

TessellateAttributes::TessellateAttributes(private_tmfs_t tmfs) :
    AttributeSubject(tmfs.tmfs)
{
    TessellateAttributes::Init();
}

// ****************************************************************************
// Method: TessellateAttributes::TessellateAttributes
//
// Purpose:
//   Copy constructor for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

TessellateAttributes::TessellateAttributes(const TessellateAttributes &obj) :
    AttributeSubject(TessellateAttributes::TypeMapFormatString)
{
    TessellateAttributes::Copy(obj);
}

// ****************************************************************************
// Method: TessellateAttributes::TessellateAttributes
//
// Purpose:
//   Copy constructor for derived classes of the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

TessellateAttributes::TessellateAttributes(const TessellateAttributes &obj, private_tmfs_t tmfs) :
    AttributeSubject(tmfs.tmfs)
{
    TessellateAttributes::Copy(obj);
}

// ****************************************************************************
// Method: TessellateAttributes::~TessellateAttributes
//
// Purpose:
//   Destructor for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

TessellateAttributes::~TessellateAttributes()
{
    // nothing here
}

// ****************************************************************************
// Method: TessellateAttributes::operator =
//
// Purpose:
//   Assignment operator for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

TessellateAttributes&
TessellateAttributes::operator = (const TessellateAttributes &obj)
{
    if (this == &obj) return *this;

    TessellateAttributes::Copy(obj);

    return *this;
}

// ****************************************************************************
// Method: TessellateAttributes::operator ==
//
// Purpose:
//   Comparison operator == for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
TessellateAttributes::operator == (const TessellateAttributes &obj) const
{
    // Create the return value
    return ((chordError == obj.chordError) &&
            (fieldCriterion == obj.fieldCriterion) &&
            (mergePoints == obj.mergePoints));
}

// ****************************************************************************
// Method: TessellateAttributes::operator !=
//
// Purpose:
//   Comparison operator != for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
TessellateAttributes::operator != (const TessellateAttributes &obj) const
{
    return !(this->operator == (obj));
}

// ****************************************************************************
// Method: TessellateAttributes::TypeName
//
// Purpose:
//   Type name method for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

const std::string
TessellateAttributes::TypeName() const
{
    return "TessellateAttributes";
}

// ****************************************************************************
// Method: TessellateAttributes::CopyAttributes
//
// Purpose:
//   CopyAttributes method for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
TessellateAttributes::CopyAttributes(const AttributeGroup *atts)
{
    if(TypeName() != atts->TypeName())
        return false;

    // Call assignment operator.
    const TessellateAttributes *tmp = (const TessellateAttributes *)atts;
    *this = *tmp;

    return true;
}

// ****************************************************************************
// Method: TessellateAttributes::CreateCompatible
//
// Purpose:
//   CreateCompatible method for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeSubject *
TessellateAttributes::CreateCompatible(const std::string &tname) const
{
    AttributeSubject *retval = 0;
    if(TypeName() == tname)
        retval = new TessellateAttributes(*this);
    // Other cases could go here too.

    return retval;
}

// ****************************************************************************
// Method: TessellateAttributes::NewInstance
//
// Purpose:
//   NewInstance method for the TessellateAttributes class.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeSubject *
TessellateAttributes::NewInstance(bool copy) const
{
    AttributeSubject *retval = 0;
    if(copy)
        retval = new TessellateAttributes(*this);
    else
        retval = new TessellateAttributes;

    return retval;
}

// ****************************************************************************
// Method: TessellateAttributes::SelectAll
//
// Purpose:
//   Selects all attributes.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void
TessellateAttributes::SelectAll()
{
    Select(ID_chordError,     (void *)&chordError);
    Select(ID_fieldCriterion, (void *)&fieldCriterion);
    Select(ID_mergePoints,    (void *)&mergePoints);
}

///////////////////////////////////////////////////////////////////////////////
// Persistence methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: TessellateAttributes::CreateNode
//
// Purpose:
//   This method creates a DataNode representation of the object so it can be saved to a config file.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
TessellateAttributes::CreateNode(DataNode *parentNode, bool completeSave, bool forceAdd)
{
    if(parentNode == 0)
        return false;

    TessellateAttributes defaultObject;
    bool addToParent = false;
    // Create a node for TessellateAttributes.
    DataNode *node = new DataNode("TessellateAttributes");

    if(completeSave || !FieldsEqual(ID_chordError, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("chordError", chordError));
    }

    if(completeSave || !FieldsEqual(ID_fieldCriterion, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("fieldCriterion", fieldCriterion));
    }

    if(completeSave || !FieldsEqual(ID_mergePoints, &defaultObject))
    {
        addToParent = true;
        node->AddNode(new DataNode("mergePoints", mergePoints));
    }


    // Add the node to the parent node.
    if(addToParent || forceAdd)
        parentNode->AddNode(node);
    else
        delete node;

    return (addToParent || forceAdd);
}

// ****************************************************************************
// Method: TessellateAttributes::SetFromNode
//
// Purpose:
//   This method sets attributes in this object from values in a DataNode representation of the object.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

void
TessellateAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("TessellateAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("chordError")) != 0)
        SetChordError(node->AsDouble());
    if((node = searchNode->GetNode("fieldCriterion")) != 0)
        SetFieldCriterion(node->AsDouble());
    if((node = searchNode->GetNode("mergePoints")) != 0)
        SetMergePoints(node->AsBool());
}

///////////////////////////////////////////////////////////////////////////////
// Set property methods
///////////////////////////////////////////////////////////////////////////////

void
TessellateAttributes::SetChordError(double chordError_)
{
    chordError = chordError_;
    Select(ID_chordError, (void *)&chordError);
}

void
TessellateAttributes::SetFieldCriterion(double fieldCriterion_)
{
    fieldCriterion = fieldCriterion_;
    Select(ID_fieldCriterion, (void *)&fieldCriterion);
}

void
TessellateAttributes::SetMergePoints(bool mergePoints_)
{
    mergePoints = mergePoints_;
    Select(ID_mergePoints, (void *)&mergePoints);
}

///////////////////////////////////////////////////////////////////////////////
// Get property methods
///////////////////////////////////////////////////////////////////////////////

double
TessellateAttributes::GetChordError() const
{
    return chordError;
}

double
TessellateAttributes::GetFieldCriterion() const
{
    return fieldCriterion;
}

bool
TessellateAttributes::GetMergePoints() const
{
    return mergePoints;
}

///////////////////////////////////////////////////////////////////////////////
// Keyframing methods
///////////////////////////////////////////////////////////////////////////////

// ****************************************************************************
// Method: TessellateAttributes::GetFieldName
//
// Purpose:
//   This method returns the name of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

std::string
TessellateAttributes::GetFieldName(int index) const
{
    switch (index)
    {
    case ID_chordError:     return "chordError";
    case ID_fieldCriterion: return "fieldCriterion";
    case ID_mergePoints:    return "mergePoints";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: TessellateAttributes::GetFieldType
//
// Purpose:
//   This method returns the type of a field given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

AttributeGroup::FieldType
TessellateAttributes::GetFieldType(int index) const
{
    switch (index)
    {
    case ID_chordError:     return FieldType_double;
    case ID_fieldCriterion: return FieldType_double;
    case ID_mergePoints:    return FieldType_bool;
    default:  return FieldType_unknown;
    }
}

// ****************************************************************************
// Method: TessellateAttributes::GetFieldTypeName
//
// Purpose:
//   This method returns the name of a field type given its index.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

std::string
TessellateAttributes::GetFieldTypeName(int index) const
{
    switch (index)
    {
    case ID_chordError:     return "double";
    case ID_fieldCriterion: return "double";
    case ID_mergePoints:    return "bool";
    default:  return "invalid index";
    }
}

// ****************************************************************************
// Method: TessellateAttributes::FieldsEqual
//
// Purpose:
//   This method compares two fields and return true if they are equal.
//
// Note:       Autogenerated by xml2atts.
//
// Programmer: xml2atts
// Creation:   omitted
//
// Modifications:
//
// ****************************************************************************

bool
TessellateAttributes::FieldsEqual(int index_, const AttributeGroup *rhs) const
{
    const TessellateAttributes &obj = *((const TessellateAttributes*)rhs);
    bool retval = false;
    switch (index_)
    {
    case ID_chordError:
        {  // new scope
        retval = (chordError == obj.chordError);
        }
        break;
    case ID_fieldCriterion:
        {  // new scope
        retval = (fieldCriterion == obj.fieldCriterion);
        }
        break;
    case ID_mergePoints:
        {  // new scope
        retval = (mergePoints == obj.mergePoints);
        }
        break;
    default: retval = false;
    }

    return retval;
}

///////////////////////////////////////////////////////////////////////////////
// User-defined methods.
///////////////////////////////////////////////////////////////////////////////

